<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <home></home>
  </div>
  <script src="./vue.js"></script>
  <script>
    // 定义局部组件
    //  $(".btn").trigger('click')
    const SubTitle = {
      template:`
        <div>
          这是儿子
          <button @click="a">按钮</button>
        </div>
      `,
      data(){
        return {
          msg:"我是子组件的数据"
        }
      },
      methods: {
        a(){
          this.$emit('b', this.msg)
        }
      }
    }
    // 定义全局组件
    const Home = {
      template:`
        <div>
          <h3>这是父组件</h3>
          {{ msg }}
          <sub-title @b="fn"></sub-title>
        </div>
        
      `,
      data(){
        return {
          msg:'我是home组件的数据'
        }
      },
      methods:{
        fn(msg){
          console.log(msg)
          this.msg = msg;
          //alert('我接收到了')
        }
      },
      components:{
        SubTitle
      }
    }
    Vue.component("Home", Home)
    const vm = new Vue({
      el:"#app"
    })
  </script>
</body>
</html>
